<!--
 * @Author: your name
 * @Date: 2021-03-16 11:32:02
 * @LastEditTime: 2022-02-27 14:11:38
 * @LastEditors: 晟松
 * @Description: In User Settings Edit
 * @FilePath: \volunteer-vue3-admin\src\components\dashboard\Shortcuts.vue
-->

<template>
    <el-row :gutter="20" style="padding-bottom: 10px">
        <el-col :span="12">
            <div class="ve-card ve_card1">
                <el-icon>
                    <football />
                </el-icon>
                <div>
                    <p>志愿服务数量</p>
                    <span>{{ volNum }}</span>
                </div>
            </div>
        </el-col>
        <el-col :span="12">
            <div class="ve-card ve_card2">
                <el-icon>
                    <user />
                </el-icon>
                <div>
                    <p>人员数量</p>
                    <span>{{ userNum }}</span>
                </div>
            </div>
        </el-col>
    </el-row>
    <el-row :gutter="20" style="padding-top: 10px">
        <el-col :span="12" @click="router.push({ name: 'AllCommunity' })">
            <div class="ve-card ve_card3">
                <el-icon>
                    <ice-cream />
                </el-icon>
                <div>
                    <p>社区总数</p>
                    <span>{{ allCommunity.res.data?.length }}</span>
                </div>
            </div>
        </el-col>
        <el-col :span="12" @click="router.push({ name: 'AllSchool' })">
            <div class="ve-card ve_card4">
                <el-icon>
                    <document />
                </el-icon>
                <div>
                    <p>学校总数</p>
                    <!-- 注意这里的特殊处理 -->
                    <span>{{ allSchool.length }}</span>
                </div>
            </div>
        </el-col>
    </el-row>
</template>

<script setup>
import { getAllResident } from "@/myApi/community";
import { getAllStudent, getAllCollegeStudent, getAllCollegeAdmin } from "@/myApi/school";
import { getCollegeAllStudentVol, getAllResidentVol } from "@/myApi/vol";
import { getAllSchool, getAllCommunity } from "../../myApi/user";
import { reactive, ref, computed, onBeforeMount } from "vue";
import { useRouter } from "vue-router";
import { useStore } from "vuex";
// 用户数
const userNum = ref(0);
// 志愿服务数量
const volNum = ref(0);

const store = useStore();
const router = useRouter();
let identity = computed(() => store.getters.identity);
// console.log("identity: ", identity.value);
let userAdmin = computed(() => store.getters.user);
let schoolAdmin = computed(() => store.getters.schoolAdmin);

// 获得社区和学校列表
let allCommunity = reactive({ res: {} });
let allSchool = reactive({ res: {}, length: 0 });
// 所有的人员及其志愿服务
let allVol = reactive({});
// 注意除了使用 <Suspense>包裹组件，可以直接在setup中使用await，不然就是只有在生命周期中使用了
onBeforeMount(async () => {
    if (identity.value == "school" && !schoolAdmin.value) {
        allVol = await getCollegeAllStudentVol({ id: userAdmin.value.id });
    } else if (identity.value == "community") {
        allVol = await getAllResidentVol({ id: userAdmin.value.id });
    } else if (identity.value == "school" && schoolAdmin.value) {
        // 校级管理员
        allVol = await getAllCollegeAdmin({ id: userAdmin.value.id });
    }
    // console.log("allVol: ", allVol);
    userNum.value = allVol.data.allLen.belongUser;
    volNum.value = allVol.data.allLen.vol;

    allCommunity.res = await getAllCommunity();
    // console.log("allCommunity: ", allCommunity);
    allSchool.res = await getAllSchool();
    // console.log("allSchool: ", allSchool);
    allSchool.length = Object.keys(allSchool.res.data).length;
});
</script>

<style lang="scss" scoped>
.el-row {
    height: 50%;

    padding-right: 10px;
}
.ve-card {
    border-radius: 10px;
    height: 100%;
    display: flex;
    align-items: center;
    transition: all 500ms;
    color: #fff;
    &:hover {
        box-shadow: 3px 3px 6px 1px rgba(0, 0, 0, 0.2);
        background: #fff;
    }
    i {
        font-size: 100px;
        margin: 0 20px;
    }
    div {
        flex: 1;
        padding-right: 12px;
        p {
            margin: 0;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }
        span {
            font-size: 60px;
            font-weight: bold;
        }
    }
}
.ve_card1 {
    background: #409eff;
    &:hover {
        color: #409eff;
    }
}
.ve_card2 {
    background: #67c23a;
    &:hover {
        color: #67c23a;
    }
}
.ve_card3 {
    background: #e6a23c;
    &:hover {
        color: #e6a23c;
    }
}
.ve_card4 {
    background: #f56c6c;
    &:hover {
        color: #f56c6c;
    }
}
</style>
